<%#
kind: registration
name: Linux registration default
model: ProvisioningTemplate
oses:
- CentOS
- Fedora
- Debian
- Ubuntu
-%>
#!/bin/bash

set -e

# This script enrolls a host with Foreman.
# Host: <%= @host.name %>

<% if @host.puppetmaster.present? -%>
<%= snippet 'puppetlabs_repo' %>
<%= snippet 'puppet_setup' %>
<% end -%>

<%= snippet 'remote_execution_ssh_keys' %>
<%= snippet 'insights' %>


# Call home to exit build mode
<% built_https = foreman_url('built').start_with?('https') -%>
<% if built_https -%>
SSL_CA_CERT=$(mktemp)
cat << EOF > $SSL_CA_CERT
<%= foreman_server_ca_cert %>
EOF
<% end -%>
curl <%= '--cacert $SSL_CA_CERT' if built_https -%> -o /dev/null --noproxy \* '<%= foreman_url('built') %>'

echo "Successfully enrolled host <%= @host.name %> with Foreman."

exit 0
